/* io */

#ifndef _BFIO_H
#define _BFIO_H

#include <stdio.h>

#define IBUFFSIZE 20

#define EOI (-1)

typedef struct inputgetter IGT;
typedef int (* Filler)(struct inputgetter* i);

struct inputgetter{
	FILE* f;	/* input file */
	Filler fillbuff;	/* fill the buffer and return the first char*/
	char* filename;
	char buff[IBUFFSIZE];	/* input buffer */
	char* pos;		/* position in buffer */ 
	int u;		/* number of chars unread */
};

IGT* iopen(IGT* i, FILE* file, char* filename);

#define igetc(i)	(--(i)->u >= 0 ? ((int)*(i)->pos++) : (i)->fillbuff(i))
#define iungetc(i)	(++(i)->u, --(i)->p)
#define iname(i)	((i)->name)

#endif	/* BFIO_H */
